//---------------Sonic CD Vert Platform Script----------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value1	:	Object.YCollisionOffset
#alias Object.Value2	:	Object.YVelocity
#alias Object.Value3	:	Object.Angle

// Property Values
#alias 0	:	START_MOVING_DOWN
#alias 1	:	START_MOVING_UP

// Collision
#alias 1	:	PLAYER_COL_FLOOR

// Ink Effect Aliases
#alias 0 : INK_NONE   // Disables transparency
#alias 1 : INK_BLEND  // Uses half transparency

sub ObjectMain
	Object.Angle   = Oscillation
	Object.Angle <<= 1

	if Object.PropertyValue == START_MOVING_UP
		Object.Angle += 256
	end if

	Sin(Object.YVelocity, Object.Angle)
	Object.YVelocity *= 0x1800
	Object.YVelocity += Object.YPos
	Object.YVelocity &= 0xFFFF0000 // Truncate the value
	Object.YVelocity -= Object.YCollisionOffset
end sub


sub ObjectPlayerInteraction
	TempValue0 = Object.YPos
	Object.YPos = Object.YCollisionOffset

	PlayerObjectCollision(C_PLATFORM, -32, -9, 32, 12)
	if CheckResult == PLAYER_COL_FLOOR
		Player.YPos += Object.YVelocity
	end if

	Object.YPos = TempValue0
end sub


sub ObjectDraw
	Sin(Object.YCollisionOffset, Object.Angle)
	Object.YCollisionOffset *= 0x1800
	Object.YCollisionOffset += Object.YPos
	Object.YCollisionOffset &= 0xFFFF0000 // Truncate the value

	DrawSpriteXY(0, Object.XPos, Object.YCollisionOffset)
end sub


sub ObjectStartup
	LoadSpriteSheet("R4.5/Objects.gif")

	SpriteFrame(-32, -9, 64, 24, 60, 1)	// #0 - Platform
end sub


// ========================
// Editor Subs
// ========================

sub RSDKEdit
	if Editor.ReturnVariable == true
		switch Editor.VariableID
		case EDIT_VAR_PROPVAL // Property Value
			CheckResult = Object.PropertyValue
			CheckResult &= 1
			break
		case 0 // startDir
			CheckResult = Object.PropertyValue
			CheckResult &= 1
			break
		end switch
	else
		switch Editor.VariableID
		case EDIT_VAR_PROPVAL // Property Value
			Object.PropertyValue = Editor.VariableValue
			Object.PropertyValue &= 1
			break
		case 0 // startDir
			Object.PropertyValue = Editor.VariableValue
			Object.PropertyValue &= 1
			break
		end switch
	end if
end sub


sub RSDKDraw
	DrawSprite(0)

	if editor.showGizmos == true
		editor.drawingOverlay = true

			TempValue0 = Object.YPos
			TempValue0 -= 0x30 0000

			TempValue1 = Object.YPos
			TempValue1 += 0x30 0000

			Object.InkEffect  = INK_BLEND

			DrawSpriteFX(0, FX_INK, Object.XPos, TempValue0)
			DrawSpriteFX(0, FX_INK, Object.XPos, TempValue1)

			Object.InkEffect  = INK_NONE

			DrawLine(Object.XPos, TempValue0, Object.XPos, TempValue1, 0xFF, 0xFF, 0xFF)
			
			
		editor.drawingOverlay = false
	end if
end sub


sub RSDKLoad
	LoadSpriteSheet("R4.5/Objects.gif")
	SpriteFrame(-32, -9, 64, 24, 60, 1)	// #0 - Platform

	AddEditorVariable("startDir")
	SetActiveVariable("startDir")
	AddEnumVariable("Up", 0)
	AddEnumVariable("Down", 1)
end sub
